import UIKit

private let checkImageViewWH: CGFloat = 22

class ImagePickerCheckCell: ImagePickerBaseCell {
    
    override var albumImage: AlbumImage? {
        willSet {
            imageView.image = newValue?.thumbnail
            checkImageView.hidden = !newValue!.isSelected
            blurredView.hidden = checkImageView.hidden
        }
    }
    
    private lazy var checkImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "checkbox_pic")
        imageView.contentMode = .ScaleAspectFill
        imageView.clipsToBounds = true
        
        return imageView
    }()
    
    private lazy var blurredView: UIView = {
       let blurredView = UIView()
        blurredView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
        
        return blurredView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(checkImageView)
        addSubview(blurredView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        checkImageView.x = width - checkImageViewWH - 5
        checkImageView.y = height - checkImageViewWH - 5
        checkImageView.width = checkImageViewWH
        checkImageView.height = checkImageViewWH
        
        blurredView.width = width
        blurredView.height = height
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
